/*
 *  composition 0038 util.h
 *  SoundController0002
 *
 *  Created by jiro on 11/09/05.
 *  Copyright 2011 jiro music. All rights reserved.
 *
 */

#pragma once

#include "../HarmonicSystem/SoundList.h"
#include "..//HarmonicSystem/Sound.h"
#include "../../sc/SoundElement.h"
#include <vector>

namespace theory0039 {

	class SequenceElement
	{
	private:

		double frequencies[ 2 ];

		double dynamics;

		int repeatCount;

	public:

		SequenceElement();

		SequenceElement( sc::Note::MidiNumber number1, double harmonics1, sc::Note::MidiNumber number2, double harmonics2, double dynamics, int repeatCount );

		void SetRepeatCount( int count );

		sc::Note::MidiNumber GetMidiNumber() const;

		double GetFrequency( int index  ) const;

		double GetDynamics() const;

		int GetRepeatCount() const;

		double GetDuration( bool isRepeat ) const;

		::sc::hs::Chord ToChord() const;

	};

	class Section
	{
	private:

		std::vector< std::vector< SequenceElement > > elementsList;

	public:

		Section();

		Section( const SequenceElement& baseElement, int partCount );

		void SetBaseElement( const SequenceElement& element );

		void SetPartCount( int count );

		void AddSubElement( const SequenceElement& element, int partIndex );
		
		void SetRepeatCountOfBaseElement( int count );

		double GetDuration( int partIndex, bool isRepeat ) const;
		
		double GetTotalDuration() const;

		double GetMaxSubElementDuration() const;

		int GetMinRepeatCountOfBaseElement() const;

		const SequenceElement& GetBaseElement() const;

		const std::vector< std::vector< SequenceElement > >& GetElements() const;

		std::vector< std::vector< const sc::SoundElement32* > > ToSoundElements( int partIndex ) const;

	private:

		std::vector< const sc::SoundElement32* > ToSoundElements( const ::sc::hs::Sound& sound, double duration ) const;

	};
}
